package com.ruoyi.binance.task;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.binance.api.OrderApi;
import com.ruoyi.binance.dingding.DingDingSendMsgUtils;
import com.ruoyi.binance.domain.BinanceMinK;
import com.ruoyi.binance.domain.BinanceTransactionConf;
import com.ruoyi.binance.domain.BinanceTransactionOrder;
import com.ruoyi.binance.mapper.BinanceMinKMapper;
import com.ruoyi.binance.mapper.BinanceTransactionConfMapper;
import com.ruoyi.binance.mapper.BinanceTransactionOrderMapper;
import com.ruoyi.binance.service.*;
import com.ruoyi.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Component
public class MonitoringTask {
    private static final Logger log = LoggerFactory.getLogger(MonitoringTask.class);

    @Autowired
    private AsyncAveragePrice averagePrice;
    @Autowired
    private BinanceMinKMapper binanceMinKMapper;
    @Autowired
    private BinanceTransactionConfMapper binanceTransactionConfMapper;
    @Autowired
    private AsyncAPriceMonitoring asyncAPriceMonitoring;
    @Autowired
    private AsyncAveBuySell asyncAveBuySell;
    @Autowired
    private AsyncAutoSingleCell asyncAutoSingleCell;
    @Autowired
    private AsyncAveBuySellPlus asyncAveBuySellPlus;
    @Autowired
    private AsyncAveragePricePlus asyncAveragePricePlus;
    @Autowired
    private Async15MACD async15MACD;

    public void monitoring(String code, Date time, BigDecimal close, BigDecimal open) {
        try {
            log.info("策略监控定时任务----------------------开始");
            BinanceTransactionConf binanceTransactionConf = new BinanceTransactionConf();
            binanceTransactionConf.setCode(code);
            binanceTransactionConf.setStatus("0");
            List<BinanceTransactionConf> binanceTransactionConfs = binanceTransactionConfMapper.selectBinanceTransactionConfList(binanceTransactionConf);
            for (BinanceTransactionConf bean : binanceTransactionConfs){
                if("price_monitoring".equals(bean.getMonitoringType())){
                    averagePrice.getAveragePrice(bean.getId(), bean.getCode(), time, close, open);
                }
                if ("a_price_monitoring".equals(bean.getMonitoringType())){
                    asyncAPriceMonitoring.getAPriceMonitoring(bean.getId(), bean.getCode(), time, close, open);
                }
                if("average_buy_sell".equals(bean.getMonitoringType())){
                    asyncAveBuySell.getAPriceMonitoring(bean.getId(), bean.getCode(), time, close, open);
                }
                if ("auto_single_cell".equals(bean.getMonitoringType())){
                    asyncAutoSingleCell.getAPriceMonitoring(bean.getId(), bean.getCode(), time, close, open);
                }
                if("average_buy_sell_plus".equals(bean.getMonitoringType())){
                    asyncAveBuySellPlus.getAveragePrice(bean.getId(), bean.getCode(), time, close, open);
                }
                if("price_monitoring_plus".equals(bean.getMonitoringType())){
                    asyncAveragePricePlus.getAveragePrice(bean.getId(), bean.getCode(), time, close, open);
                }
                if ("15_macd".equals(bean.getMonitoringType())){
                    async15MACD.getAPriceMonitoring(bean.getId(), bean.getCode(), time, close, open);
                }
            }
            log.info("策略监控定时任务----------------------结束");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
